package com.ruoyi.project.play.service.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.play.service.domain.ServiceObject;
import com.ruoyi.project.play.service.service.IServiceObjectService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 服务项目Controller
 * 
 * @author wyh
 * @date 2024-07-07
 */
@RestController
@RequestMapping("/play/service")
public class ServiceObjectController extends BaseController
{
    @Autowired
    private IServiceObjectService serviceObjectService;

    /**
     * 查询服务项目列表
     */
    @PreAuthorize("@ss.hasPermi('play:service:list')")
    @GetMapping("/list")
    public AjaxResult list(ServiceObject serviceObject)
    {
        List<ServiceObject> list = serviceObjectService.selectServiceObjectList(serviceObject);
        return success(list);
    }

    /**
     * 导出服务项目列表
     */
    @PreAuthorize("@ss.hasPermi('play:service:export')")
    @Log(title = "服务项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceObject serviceObject)
    {
        List<ServiceObject> list = serviceObjectService.selectServiceObjectList(serviceObject);
        ExcelUtil<ServiceObject> util = new ExcelUtil<ServiceObject>(ServiceObject.class);
        util.exportExcel(response, list, "服务项目数据");
    }

    /**
     * 获取服务项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('play:service:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(serviceObjectService.selectServiceObjectById(id));
    }

    /**
     * 新增服务项目
     */
    @PreAuthorize("@ss.hasPermi('play:service:add')")
    @Log(title = "服务项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceObject serviceObject)
    {
        return toAjax(serviceObjectService.insertServiceObject(serviceObject));
    }

    /**
     * 修改服务项目
     */
    @PreAuthorize("@ss.hasPermi('play:service:edit')")
    @Log(title = "服务项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceObject serviceObject)
    {
        return toAjax(serviceObjectService.updateServiceObject(serviceObject));
    }

    /**
     * 删除服务项目
     */
    @PreAuthorize("@ss.hasPermi('play:service:remove')")
    @Log(title = "服务项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(serviceObjectService.deleteServiceObjectByIds(ids));
    }
}
